package com.hmdp.controller;


import com.hmdp.dto.Result;
import com.hmdp.service.IFollowService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 */
@RestController
@RequestMapping("/follow")
@Slf4j
public class FollowController {

    @Autowired
    IFollowService followService;

    /**
     * 进行关注和取关操作
     * @param followId
     * @param isFollowed
     * @return
     */
    @PutMapping("/{followId}/{isFollowed}")
    public Result follow(@PathVariable Long followId, @PathVariable Boolean isFollowed) {
        log.info("关注和取关， 被关注对象id为：{}， 是否被关注：{}", followId, isFollowed);
        return followService.follow(followId, isFollowed);
    }

    /**
     * 判断当前登录用户是已否关注
     * @param followId
     * @return
     */
    @GetMapping("/or/not/{id}")
    public Result queryIsFollowed(@PathVariable("id") Long followId){
        log.info("判断是否已关注，关注的人id为：{}", followId);
        return followService.queryIsFollowed(followId);
    }

    /**
     * 判断共同关注
     * @param followId
     */
    @GetMapping("/common/{id}")
    public Result queryCommonFollow(@PathVariable("id") Long followId){
        log.info("判断共同关注，目标用户id为：{}", followId);
        return followService.queryCommonFollow(followId);
    }
}
